package com.ifnk.portaljava.dapWeb.pacp;
/**
 * <p>Title: pcap文件头类</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2010</p>
 *
 * <p>Company: </p>
 *
 * @author WenSheng.Song.hlyt@gmail.com
 * @version 1.0
 */
import com.ifnk.portaljava.dapWeb.dataPacket.TransformFunction;

public class Pacp_file_header {
	private byte[] magic = new byte[] { -44, -61, -78, -95 };// 十六进制d4 c3 b2
																// a1
	private short major = 512;// 十六进制02 00
	private short minor = 1024;// 十六进制04 00
	private int thiszone = 0;
	private int sigfigs = 0;
	private int snaplen = 2097152;
	private int linktype = 16777216;
/*
 * magic：   4字节 pcap文件标识 目前为“d4 c3 b2 a1”
 major：   2字节 主版本号     #define PCAP_VERSION_MAJOR 2
 minor：   2字节 次版本号     #define PCAP_VERSION_MINOR 4
 thiszone：4字节 时区修正     并未使用，目前全为0
 sigfigs： 4字节 精确时间戳   并未使用，目前全为0
 snaplen： 4字节 抓包最大长度 如果要抓全，设为0x0000ffff（65535），
          tcpdump -s 0就是设置这个参数，缺省为68字节
 linktype：4字节 链路类型    一般都是1：ethernet

 */
	public byte[] getMagic() {
		return magic;
	}

	public void setMagic(byte[] magic) {
		this.magic = magic;
	}

	public short getMajor() {
		return major;
	}

	public void setMajor(short major) {
		this.major = major;
	}

	public short getMinor() {
		return minor;
	}

	public void setMinor(short minor) {
		this.minor = minor;
	}

	public int getThiszone() {
		return thiszone;
	}

	public void setThiszone(int thiszone) {
		this.thiszone = thiszone;
	}

	public int getSigfigs() {
		return sigfigs;
	}

	public void setSigfigs(int sigfigs) {
		this.sigfigs = sigfigs;
	}

	public int getSnaplen() {
		return snaplen;
	}

	public void setSnaplen(int snaplen) {
		this.snaplen = snaplen;
	}

	public int getLinktype() {
		return linktype;
	}

	public void setLinktype(int linktype) {
		this.linktype = linktype;
	}

	public Pacp_file_header(byte[] magic, short major, short minor,
			int thiszone, int sigfigs, int snaplen, int linktype) {
		super();
		this.magic = magic;
		this.major = major;
		this.minor = minor;
		this.thiszone = thiszone;
		this.sigfigs = sigfigs;
		this.snaplen = snaplen;
		this.linktype = linktype;
	}

	public Pacp_file_header() {
		super();
	}

	public byte[] fileHeader() {
		byte[] header = new byte[24];
		System.arraycopy(this.magic, 0, header, 0, 4);
		byte[] majorByte = TransformFunction.shortToByteArray(this.major);
		System.arraycopy(majorByte, 0, header, 4, 2);
		byte[] minorByte = TransformFunction.shortToByteArray(this.minor);
		System.arraycopy(minorByte, 0, header, 6, 2);
		byte[] thiszoneByte = TransformFunction.intToByteArray(this.thiszone);
		System.arraycopy(thiszoneByte, 0, header, 8, 4);
		byte[] sigfigsByte = TransformFunction.intToByteArray(this.sigfigs);
		System.arraycopy(sigfigsByte, 0, header, 12, 4);
		byte[] snaplenByte = TransformFunction.intToByteArray(this.snaplen);
		System.arraycopy(snaplenByte, 0, header, 16, 4);
		byte[] linktypeByte = TransformFunction.intToByteArray(this.linktype);
		System.arraycopy(linktypeByte, 0, header, 20, 4);
		return header;
	}

}
